package com.grj.example;

/**
 * @author ganru
 * @date 2025/10/19 0:45
 */
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

//public class ProducerExample {
//    public static void main(String[] args) {
//        Properties props = new Properties();
//        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
//        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
//        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
//        props.put(ProducerConfig.ACKS_CONFIG, "all");
//
//        KafkaProducer<String, String> producer = new KafkaProducer<>(props);
//        for (int i = 0; i < 5; i++) {
//            producer.send(new ProducerRecord<>("test-topic", "key-" + i, "hello kafka " + i));
//        }
//        producer.close();
//        System.out.println("✅ Sent messages successfully!");
//    }
//}
